package minicat.coyote.components;

import minicat.catalina.components.Server;

import java.io.InputStream;
import java.net.Socket;

public class Processor extends Thread {

    private Socket socket;
    private Server server;
    private Request request;
    private Response response;

    public Processor(Socket socket, Server server) {
        this.socket = socket;
        this.server = server;
    }

    @Override
    public void run() {
        try{
            InputStream inputStream = socket.getInputStream();
            // 封装Request对象和Response对象
            this.request = new Request(inputStream);
            this.response = new Response(socket.getOutputStream());

            CoyoteAdapter.mapping(this.server, this.request, this.response);

            socket.close();

        }catch (Exception e) {
            e.printStackTrace();
        }

    }
}
